﻿using Illinois.Core.Interfaces;
using Illinois.Core.Models;
using Illinois.Core.Services;
using Moq;
using NUnit.Framework;

namespace Illinois.Core.Test.Services
{
  [TestFixture]
  public class Test_LogInService
  {
    private Mock<IUserService> _userService;
    private LogInService _logInService;
    const string Password = "test"; // todo: encode it in md5

    [SetUp]
    public void Init()
    {
      _userService = new Mock<IUserService>();
      _logInService = new LogInService(_userService.Object);
    }

    [Test]
    public void When_I_Log_As_Mattia_Richetto_I_Belong_To_ARENA()
    {
      // arrange
      const string username = "mattia.richetto";
      const string prjName = "ARENA";
      var fake = new User { Project = new Project { Name = prjName } };
      _userService.Setup(e => e.GetUser(username, Password)).Returns(fake);
      // act
      var user = _logInService.LogIn(username, Password);
      var name = user.Project.Name;
      // assert
      Assert.AreEqual(prjName, name);
    }

    [Test]
    public void When_I_Log_As_MariaElisa_Cardone_I_Belong_To_EBS()
    {
      // arrange
      const string username = "mariaelisa.cardone";
      const string prjName = "EBS";
      var fake = new User { Project = new Project { Name = prjName } };
      _userService.Setup(e => e.GetUser(username, Password)).Returns(fake);
      // act
      var user = _logInService.LogIn(username, Password);
      var name = user.Project.Name;
      // assert
      Assert.AreEqual(prjName, name);
    }
  }
}
